package com.typhoon.spring_shiro.utils;

import org.apache.shiro.SecurityUtils;

import com.typhoon.spring_shiro.dto.UserDto;

/**
 * shiro会话管理工具类
 * @author Typhoon
 *
 */
public class GlobalVarGetter {

    public static UserDto getUser() {
        return ((UserDto)SecurityUtils.getSubject().getSession().getAttribute("user"));
    }
    
    public static Long getUserId() {
        return ((UserDto)SecurityUtils.getSubject().getSession().getAttribute("user")).getId();
    }
    
    public static void setAttribute(Object key, Object value) {
        SecurityUtils.getSubject().getSession().setAttribute(key, value);
    }
    
    public static Object getAttribute(Object key) {
        return SecurityUtils.getSubject().getSession().getAttribute(key);
    }
    
}
